#include "index.h"

using namespace std;
using namespace easyWebServer;


void Index::_404()
{
    string context("<h1> 404 Not Find </h1>");
    m_response->insertPair("Content-Length", to_string(context.size()));
    m_response->setContext(context, "404");
}

void Index::index()
{
    string context;
    fstream in;
    stringstream ss;
    in.open("./index_.html", ios_base::in);
    ss << in.rdbuf();
    context = ss.str();
    in.close();
    m_response->insertPair("Content-Length", to_string(context.size()));
    m_response->setContext(context, "200 OK");
}

void Index::pic()
{
    m_fileSystem->find(Singleton<yazi::json::Json>::getInstance()["root"].asString() + "/paiDaXing.jpg");
    m_response->setFileFd(m_fileSystem->getFileFd());
    m_response->insertPair("Content-Length", to_string(m_fileSystem->getFileSize()));
    m_response->setContext("", "200 OK");   
}

void Index::demoPage()
{
    m_fileSystem->find(Singleton<yazi::json::Json>::getInstance()["root"].asString() + "/index.html");
    m_response->setFileFd(m_fileSystem->getFileFd());
    m_response->insertPair("Content-Length", to_string(m_fileSystem->getFileSize()));
    m_response->insertPair("Content-Type", "text/html");
    m_response->setContext("", "200 OK");
}



